```html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>消息模型与交换机类型 | RabbitMQ 深度解析</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            color: #333;
            line-height: 1.6;
        }
        h1, h2, h3, h4 {
            font-family: 'Noto Serif SC', serif;
            font-weight: 600;
            color: #222;
        }
        .hero {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        .exchange-card {
            transition: all 0.3s ease;
            border-left: 4px solid;
        }
        .exchange-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 10px 25px rgba(0,0,0,0.1);
        }
        .direct-card {
            border-left-color: #4f46e5;
        }
        .fanout-card {
            border-left-color: #10b981;
        }
        .topic-card {
            border-left-color: #f59e0b;
        }
        .headers-card {
            border-left-color: #8b5cf6;
        }
        .feature-icon {
            width: 48px;
            height: 48px;
            display: flex;
            align-items: center;
            justify-content: center;
            border-radius: 12px;
            margin-bottom: 1rem;
        }
        .direct-icon {
            background-color: rgba(79, 70, 229, 0.1);
            color: #4f46e5;
        }
        .fanout-icon {
            background-color: rgba(16, 185, 129, 0.1);
            color: #10b981;
        }
        .topic-icon {
            background-color: rgba(245, 158, 11, 0.1);
            color: #f59e0b;
        }
        .headers-icon {
            background-color: rgba(139, 92, 246, 0.1);
            color: #8b5cf6;
        }
        .diagram-container {
            background: #f8fafc;
            border-radius: 0.5rem;
            padding: 1.5rem;
            margin: 2rem 0;
        }
        .footer {
            background-color: #1a1a1a;
        }
        .footer a:hover {
            color: #a5b4fc;
        }
        .prose a {
            color: #4f46e5;
            text-decoration: none;
            font-weight: 500;
        }
        .prose a:hover {
            text-decoration: underline;
        }
        .prose ul {
            list-style-type: none;
            padding-left: 1.5rem;
        }
        .prose ul li:before {
            content: "•";
            color: #4f46e5;
            font-weight: bold;
            display: inline-block;
            width: 1em;
            margin-left: -1em;
        }
        .prose code {
            background-color: #f3f4f6;
            padding: 0.2em 0.4em;
            border-radius: 0.25rem;
            font-family: monospace;
            font-size: 0.9em;
        }
    </style>
</head>
<body class="bg-gray-50">
    <!-- Hero Section -->
    <section class="hero text-white py-20 px-4 md:px-0">
        <div class="container mx-auto max-w-5xl">
            <div class="text-center">
                <h1 class="text-4xl md:text-5xl font-bold mb-6">消息模型与交换机类型</h1>
                <p class="text-xl md:text-2xl opacity-90 mb-8 max-w-3xl mx-auto">RabbitMQ 消息路由机制深度解析</p>
                <div class="inline-flex items-center space-x-2 bg-white bg-opacity-20 px-4 py-2 rounded-full">
                    <i class="fas fa-book-open"></i>
                    <span>分布式系统核心技术</span>
                </div>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <main class="container mx-auto max-w-5xl px-4 py-12">
        <article class="prose prose-lg max-w-none">
            <!-- Introduction -->
            <section class="mb-16">
                <p class="text-lg text-gray-600 mb-6">
                    在现代分布式系统的架构设计中，消息队列作为系统间异步通信的重要组成部分，已经成为关键技术。RabbitMQ 作为流行的消息中间件之一，其核心在于灵活的消息路由机制，而交换机（Exchange）正是这一机制的核心组件。
                </p>
                
                <div class="bg-blue-50 border-l-4 border-blue-500 p-6 rounded-r-lg mb-8">
                    <div class="flex">
                        <div class="flex-shrink-0">
                            <i class="fas fa-lightbulb text-blue-500 text-2xl"></i>
                        </div>
                        <div class="ml-3">
                            <h3 class="text-lg font-medium text-blue-800">核心概念</h3>
                            <p class="mt-2 text-blue-700">
                                交换机的作用是决定消息应该被路由到哪个队列，而这个路由规则是通过交换机的类型来确定的。RabbitMQ 提供了四种不同类型的交换机，每种类型都有其独特的路由策略和使用场景。
                            </p>
                        </div>
                    </div>
                </div>

                <div class="diagram-container">
                    <div class="mermaid">
                        graph LR
                            P[Producer] --> E[Exchange]
                            E -->|Direct| Q1[Queue 1]
                            E -->|Fanout| Q2[Queue 2]
                            E -->|Topic| Q3[Queue 3]
                            E -->|Headers| Q4[Queue 4]
                            Q1 --> C1[Consumer]
                            Q2 --> C2[Consumer]
                            Q3 --> C3[Consumer]
                            Q4 --> C4[Consumer]
                    </div>
                </div>
            </section>

            <!-- Exchange Types Overview -->
            <section class="mb-16">
                <h2 class="text-3xl font-bold mb-8 border-b pb-4">交换机类型概述</h2>
                
                <div class="grid md:grid-cols-2 gap-6 mb-12">
                    <div class="exchange-card direct-card bg-white p-6 rounded-lg shadow-sm">
                        <div class="feature-icon direct-icon">
                            <i class="fas fa-route text-2xl"></i>
                        </div>
                        <h3 class="text-xl font-bold mb-3">Direct Exchange</h3>
                        <p class="text-gray-600 mb-4">基于路由键的精确匹配，将消息路由到指定的队列。</p>
                        <div class="text-indigo-600 font-medium">
                            <i class="fas fa-check-circle mr-2"></i>
                            <span>典型应用：任务分发、日志分类</span>
                        </div>
                    </div>
                    
                    <div class="exchange-card fanout-card bg-white p-6 rounded-lg shadow-sm">
                        <div class="feature-icon fanout-icon">
                            <i class="fas fa-broadcast-tower text-2xl"></i>
                        </div>
                        <h3 class="text-xl font-bold mb-3">Fanout Exchange</h3>
                        <p class="text-gray-600 mb-4">将消息广播到所有绑定的队列，不关心路由键。</p>
                        <div class="text-emerald-600 font-medium">
                            <i class="fas fa-check-circle mr-2"></i>
                            <span>典型应用：事件通知、日志收集</span>
                        </div>
                    </div>
                    
                    <div class="exchange-card topic-card bg-white p-6 rounded-lg shadow-sm">
                        <div class="feature-icon topic-icon">
                            <i class="fas fa-project-diagram text-2xl"></i>
                        </div>
                        <h3 class="text-xl font-bold mb-3">Topic Exchange</h3>
                        <p class="text-gray-600 mb-4">基于模式匹配的路由键，支持通配符。</p>
                        <div class="text-amber-600 font-medium">
                            <i class="fas fa-check-circle mr-2"></i>
                            <span>典型应用：复杂消息路由、多级分类</span>
                        </div>
                    </div>
                    
                    <div class="exchange-card headers-card bg-white p-6 rounded-lg shadow-sm">
                        <div class="feature-icon headers-icon">
                            <i class="fas fa-heading text-2xl"></i>
                        </div>
                        <h3 class="text-xl font-bold mb-3">Headers Exchange</h3>
                        <p class="text-gray-600 mb-4">基于消息头部的属性匹配进行路由。</p>
                        <div class="text-purple-600 font-medium">
                            <i class="fas fa-check-circle mr-2"></i>
                            <span>典型应用：多条件筛选、属性路由</span>
                        </div>
                    </div>
                </div>
            </section>

            <!-- Direct Exchange Section -->
            <section class="mb-16">
                <h2 class="text-3xl font-bold mb-6 border-b pb-4">Direct Exchange（直接交换机）</h2>
                
                <div class="flex items-start mb-8">
                    <div class="flex-shrink-0 bg-indigo-100 p-3 rounded-lg mr-4">
                        <i class="fas fa-route text-indigo-600 text-xl"></i>
                    </div>
                    <div>
                        <p class="text-gray-700">
                            Direct Exchange 是 RabbitMQ 中最简单的一种交换机类型。它的功能非常直接：根据<strong>精确匹配</strong>的路由键（routing key）将消息路由到一个或多个队列。
                        </p>
                    </div>
                </div>

                <h3 class="text-2xl font-semibold mt-8 mb-4 text-gray-800">工作原理</h3>
                <ul class="mb-6">
                    <li class="mb-2"><strong>生产者发送消息</strong>：生产者将消息发送到 Direct Exchange，并在消息上附带一个路由键。</li>
                    <li class="mb-2"><strong>消费者绑定队列</strong>：消费者在绑定队列时，指定一个路由键。</li>
                    <li class="mb-2"><strong>交换机路由消息</strong>：Direct Exchange 根据消息的路由键与队列的绑定键进行精确匹配。</li>
                </ul>

                <h3 class="text-2xl font-semibold mt-8 mb-4 text-gray-800">特点</h3>
                <div class="grid md:grid-cols-3 gap-4 mb-8">
                    <div class="bg-indigo-50 p-4 rounded-lg">
                        <h4 class="font-medium text-indigo-800 mb-2">精确匹配</h4>
                        <p class="text-gray-700">路由键必须完全匹配才能传递消息</p>
                    </div>
                    <div class="bg-indigo-50 p-4 rounded-lg">
                        <h4 class="font-medium text-indigo-800 mb-2">灵活性</h4>
                        <p class="text-gray-700">一个交换机可绑定多个队列</p>
                    </div>
                    <div class="bg-indigo-50 p-4 rounded-lg">
                        <h4 class="font-medium text-indigo-800 mb-2">高效性</h4>
                        <p class="text-gray-700">路由过程简单高效</p>
                    </div>
                </div>

                <h3 class="text-2xl font-semibold mt-8 mb-4 text-gray-800">使用场景</h3>
                <div class="grid md:grid-cols-3 gap-4 mb-8">
                    <div class="border p-4 rounded-lg">
                        <h4 class="font-medium mb-2">日志系统</h4>
                        <p class="text-gray-600 text-sm">不同级别日志路由到不同队列</p>
                    </div>
                    <div class="border p-4 rounded-lg">
                        <h4 class="font-medium mb-2">任务分发</h4>
                        <p class="text-gray-600 text-sm">不同类型任务分发到专属队列</p>
                    </div>
                    <div class="border p-4 rounded-lg">
                        <h4 class="font-medium mb-2">微服务通信</h4>
                        <p class="text-gray-600 text-sm">服务间精确消息传递</p>
                    </div>
                </div>

                <h3 class="text-2xl font-semibold mt-8 mb-4 text-gray-800">代码示例</h3>
                <div class="bg-gray-800 rounded-lg p-4 mb-8">
                    <pre class="text-gray-300 overflow-x-auto"><code>// 生产者发送消息
channel.basicPublish("task_exchange", "email", null, "Send email task".getBytes());

// 消费者绑定队列并接收消息
channel.queueBind("task_queue_email", "task_exchange", "email");
channel.basicConsume("task_queue_email", true, (consumerTag, delivery) -> {
    String message = new String(delivery.getBody(), "UTF-8");
    System.out.println("Received email task: " + message);
});</code></pre>
                </div>

                <div class="diagram-container">
                    <div class="mermaid">
                        graph LR
                            P[Producer] -->|routing_key: email| E[Direct Exchange]
                            E -->|email| Q1[Email Queue]
                            E -->|sms| Q2[SMS Queue]
                            E -->|push| Q3[Push Queue]
                            Q1 --> C1[Consumer]
                            Q2 --> C2[Consumer]
                            Q3 --> C3[Consumer]
                    </div>
                </div>
            </section>

            <!-- Fanout Exchange Section -->
            <section class="mb-16">
                <h2 class="text-3xl font-bold mb-6 border-b pb-4">Fanout Exchange（扇出交换机）</h2>
                
                <div class="flex items-start mb-8">
                    <div class="flex-shrink-0 bg-emerald-100 p-3 rounded-lg mr-4">
                        <i class="fas fa-broadcast-tower text-emerald-600 text-xl"></i>
                    </div>
                    <div>
                        <p class="text-gray-700">
                            Fanout Exchange 具有广播的特性，能够将收到的消息路由到所有绑定的队列中，无论队列的路由键是什么。这种交换机类型适合于需要将消息传递给多个消费者的场景。
                        </p>
                    </div>
                </div>

                <h3 class="text-2xl font-semibold mt-8 mb-4 text-gray-800">工作原理</h3>
                <ul class="mb-6">
                    <li class="mb-2"><strong>生产者发送消息</strong>：生产者将消息发送到 Fanout Exchange，消息没有指定路由键。</li>
                    <li class="mb-2"><strong>消费者绑定队列</strong>：消费者将自己的队列绑定到 Fanout Exchange，不指定路由键。</li>
                    <li class="mb-2"><strong>交换机路由消息</strong>：Fanout Exchange 会将所有进入的消息广播到与其绑定的所有队列。</li>
                </ul>

                <h3 class="text-2xl font-semibold mt-8 mb-4 text-gray-800">特点</h3>
                <div class="grid md:grid-cols-3 gap-4 mb-8">
                    <div class="bg-emerald-50 p-4 rounded-lg">
                        <h4 class="font-medium text-emerald-800 mb-2">广播性质</h4>
                        <p class="text-gray-700">消息发送到所有绑定的队列</p>
                    </div>
                    <div class="bg-emerald-50 p-4 rounded-lg">
                        <h4 class="font-medium text-emerald-800 mb-2">简单高效</h4>
                        <p class="text-gray-700">不需要匹配路由键</p>
                    </div>
                    <div class="bg-emerald-50 p-4 rounded-lg">
                        <h4 class="font-medium text-emerald-800 mb-2">无路由键</h4>
                        <p class="text-gray-700">不依赖路由键做决策</p>
                    </div>
                </div>

                <h3 class="text-2xl font-semibold mt-8 mb-4 text-gray-800">使用场景</h3>
                <div class="grid md:grid-cols-3 gap-4 mb-8">
                    <div class="border p-4 rounded-lg">
                        <h4 class="font-medium mb-2">日志收集</h4>
                        <p class="text-gray-600 text-sm">多个队列同时收集日志</p>
                    </div>
                    <div class="border p-4 rounded-lg">
                        <h4 class="font-medium mb-2">消息通知</h4>
                        <p class="text-gray-600 text-sm">通知多个接收者</p>
                    </div>
                    <div class="border p-4 rounded-lg">
                        <h4 class="font-medium mb-2">发布/订阅</h4>
                        <p class="text-gray-600 text-sm">实现发布订阅模式</p>
                    </div>
                </div>

                <h3 class="text-2xl font-semibold mt-8 mb-4 text-gray-800">代码示例</h3>
                <div class="bg-gray-800 rounded-lg p-4 mb-8">
                    <pre class="text-gray-300 overflow-x-auto"><code>// 生产者发送消息
channel.basicPublish("log_exchange", "", null, "Log Message".getBytes());

// 消费者绑定队列并接收消息
channel.queueBind("info_log_queue", "log_exchange", "");
channel.basicConsume("info_log_queue", true, (consumerTag, delivery) -> {
    String message = new String(delivery.getBody(), "UTF-8");
    System.out.println("Received info log: " + message);
});</code></pre>
                </div>

                <div class="diagram-container">
                    <div class="mermaid">
                        graph LR
                            P[Producer] --> E[Fanout Exchange]
                            E --> Q1[Queue 1]
                            E --> Q2[Queue 2]
                            E --> Q3[Queue 3]
                            Q1 --> C1[Consumer]
                            Q2 --> C2[Consumer]
                            Q3 --> C3[Consumer]
                    </div>
                </div>
            </section>

            <!-- Topic Exchange Section -->
            <section class="mb-16">
                <h2 class="text-3xl font-bold mb-6 border-b pb-4">Topic Exchange（主题交换机）</h2>
                
                <div class="flex items-start mb-8">
                    <div class="flex-shrink-0 bg-amber-100 p-3 rounded-lg mr-4">
                        <i class="fas fa-project-diagram text-amber-600 text-xl"></i>
                    </div>
                    <div>
                        <p class="text-gray-700">
                            Topic Exchange 使用路由键的模式匹配来路由消息。它允许使用通配符（如 <code>*</code> 和 <code>#</code>）来匹配多个路由键，从而提供灵活的消息路由功能。
                        </p>
                    </div>
                </div>

                <h3 class="text-2xl font-semibold mt-8 mb-4 text-gray-800">通配符规则</h3>
                <div class="grid md:grid-cols-2 gap-4 mb-8">
                    <div class="bg-amber-50 p-4 rounded-lg">
                        <h4 class="font-medium text-amber-800 mb-2"><code>*</code> (星号)</h4>
                        <p class="text-gray-700">匹配一个单词（一个由点号分隔的部分）</p>
                        <p class="text-gray-600 text-sm mt-2">示例: <code>sports.*</code> 匹配 <code>sports.football</code> 但不匹配 <code>sports.football.news</code></p>
                    </div>
                    <div class="bg-amber-50 p-4 rounded-lg">
                        <h4 class="font-medium text-amber-800 mb-2"><code>#</code> (井号)</h4>
                        <p class="text-gray-700">匹配零个或多个单词</p>
                        <p class="text-gray-600 text-sm mt-2">示例: <code>sports.#</code> 匹配 <code>sports</code>, <code>sports.football</code>, <code>sports.football.news</code></p>
                    </div>
                </div>

                <h3 class="text-2xl font-semibold mt-8 mb-4 text-gray-800">特点</h3>
                <div class="grid md:grid-cols-3 gap-4 mb-8">
                    <div class="bg-amber-50 p-4 rounded-lg">
                        <h4 class="font-medium text-amber-800 mb-2">灵活路由</h4>
                        <p class="text-gray-700">支持通配符匹配</p>
                    </div>
                    <div class="bg-amber-50 p-4 rounded-lg">
                        <h4 class="font-medium text-amber-800 mb-2">精确与模糊匹配</h4>
                        <p class="text-gray-700">支持多级匹配</p>
                    </div>
                    <div class="bg-amber-50 p-4 rounded-lg">
                        <h4 class="font-medium text-amber-800 mb-2">发布/订阅</h4>
                        <p class="text-gray-700">适合主题订阅</p>
                    </div>
                </div>

                <h3 class="text-2xl font-semibold mt-8 mb-4 text-gray-800">使用场景</h3>
                <div class="grid md:grid-cols-3 gap-4 mb-8">
                    <div class="border p-4 rounded-lg">
                        <h4 class="font-medium mb-2">日志系统</h4>
                        <p class="text-gray-600 text-sm">按级别和类型分类日志</p>
                    </div>
                    <div class="border p-4 rounded-lg">
                        <h4 class="font-medium mb-2">事件系统</h4>
                        <p class="text-gray-600 text-sm">基于事件类型路由</p>
                    </div>
                    <div class="border p-4 rounded-lg">
                        <h4 class="font-medium mb-2">应用监控</h4>
                        <p class="text-gray-600 text-sm">按监控项路由数据</p>
                    </div>
                </div>

                <h3 class="text-2xl font-semibold mt-8 mb-4 text-gray-800">代码示例</h3>
                <div class="bg-gray-800 rounded-lg p-4 mb-8">
                    <pre class="text-gray-300 overflow-x-auto"><code>// 创建交换机（topic类型）
channel.exchangeDeclare("log_exchange", "topic");

// 绑定队列到交换机，并指定路由键
channel.queueBind("info_log_queue", "log_exchange", "log.info");
channel.queueBind("error_log_queue", "log_exchange", "log.error");
channel.queueBind("debug_log_queue", "log_exchange", "log.debug");

// 发送消息
String logMessage = "This is an info log message";
channel.basicPublish("log_exchange", "log.info", null, logMessage.getBytes());</code></pre>
                </div>

                <div class="diagram-container">
                    <div class="mermaid">
                        graph LR
                            P[Producer] -->|routing_key: log.info| E[Topic Exchange]
                            E -->|log.*| Q1[Log Queue]
                            E -->|log.error| Q2[Error Queue]
                            E -->|log.#| Q3[All Logs Queue]
                            Q1 --> C1[Consumer]
                            Q2 --> C2[Consumer]
                            Q3 --> C3[Consumer]
                    </div>
                </div>
            </section>

            <!-- Headers Exchange Section -->
            <section class="mb-16">
                <h2 class="text-3xl font-bold mb-6 border-b pb-4">Headers Exchange（头交换机）</h2>
                
                <div class="flex items-start mb-8">
                    <div class="flex-shrink-0 bg-purple-100 p-3 rounded-lg mr-4">
                        <i class="fas fa-heading text-purple-600 text-xl"></i>
                    </div>
                    <div>
                        <p class="text-gray-700">
                            Headers Exchange 通过消息的 <strong>头部信息</strong> 来进行消息的路由。与其它交换机类型不同，它不关注路由键，而是根据消息头部的键值对来决定消息的路由目标。
                        </p>
                    </div>
                </div>

                <h3 class="text-2xl font-semibold mt-8 mb-4 text-gray-800">匹配规则</h3>
                <div class="grid md:grid-cols-2 gap-4 mb-8">
                    <div class="bg-purple-50 p-4 rounded-lg">
                        <h4 class="font-medium text-purple-800 mb-2"><code>x-match: all</code></h4>
                        <p class="text-gray-700">消息头部中的所有键必须与队列绑定的键完全匹配</p>
                    </div>
                    <div class="bg-purple-50 p-4 rounded-lg">
                        <h4 class="font-medium text-purple-800 mb-2"><code>x-match: any</code></h4>
                        <p class="text-gray-700">消息头部中只要有一个键匹配队列绑定的键</p>
                    </div>
                </div>

                <h3 class="text-2xl font-semibold mt-8 mb-4 text-gray-800">应用场景</h3>
                <div class="grid md:grid-cols-2 gap-4 mb-8">
                    <div class="border p-4 rounded-lg">
                        <h4 class="font-medium mb-2">复杂路由</h4>
                        <p class="text-gray-600">需要根据多个头部字段进行路由决策</p>
                    </div>
                    <div class="border p-4 rounded-lg">
                        <h4 class="font-medium mb-2">按属性过滤</h4>
                        <p class="text-gray-600">根据消息属性而非路由键进行路由</p>
                    </div>
                </div>

                <h3 class="text-2xl font-semibold mt-8 mb-4 text-gray-800">配置示例</h3>
                <div class="bg-gray-800 rounded-lg p-4 mb-8">
                    <pre class="text-gray-300 overflow-x-auto"><code>// 创建连接、通道和交换机
Channel channel = connection.createChannel();
channel.exchangeDeclare("myHeadersExchange", "headers");

// 创建队列并绑定
channel.queueDeclare("myQueue", false, false, false, null);
Map&lt;String, Object&gt; headers = new HashMap&lt;&gt;();
headers.put("color", "red");
headers.put("type", "urgent");
channel.queueBind("myQueue", "myHeadersExchange", "", headers);</code></pre>
                </div>

                <div class="diagram-container">
                    <div class="mermaid">
                        graph LR
                            P[Producer] -->|headers: color=red, type=urgent| E[Headers Exchange]
                            E -->|match: all| Q1[Queue 1]
                            E -->|match: any| Q2[Queue 2]
                            Q1 --> C1[Consumer]
                            Q2 --> C2[Consumer]
                    </div>
                </div>
            </section>

            <!-- Exchange Bindings Section -->
            <section class="mb-16">
                <h2 class="text-3xl font-bold mb-6 border-b pb-4">交换机与队列的绑定</h2>
                
                <p class="text-gray-700 mb-6">
                    在 RabbitMQ 中，交换机（Exchange）和队列（Queue）之间的关系通过 <strong>绑定（Binding）</strong> 来建立。绑定定义了交换机如何将消息传递给队列。
                </p>

                <h3 class="text-2xl font-semibold mt-8 mb-4 text-gray-800">绑定类型</h3>
                <div class="grid md:grid-cols-2 gap-6 mb-8">
                    <div class="border p-6 rounded-lg">
                        <h4 class="font-bold text-lg mb-3">Direct Exchange 绑定</h4>
                        <pre class="bg-gray-100 p-4 rounded text-sm"><code>channel.queueBind("queue1", "directExchange", "info");</code></pre>
                        <p class="text-gray-600 mt-3">队列只会接收到路由键为"info"的消息</p>
                    </div>
                    <div class="border p-6 rounded-lg">
                        <h4 class="font-bold text-lg mb-3">Fanout Exchange 绑定</h4>
                        <pre class="bg-gray-100 p-4 rounded text-sm"><code>channel.queueBind("queue1", "fanoutExchange", "");</code></pre>
                        <p class="text-gray-600 mt-3">队列会接收到所有消息（广播）</p>
                    </div>
                    <div class="border p-6 rounded-lg">
                        <h4 class="font-bold text-lg mb-3">Topic Exchange 绑定</h4>
                        <pre class="bg-gray-100 p-4 rounded text-sm"><code>channel.queueBind("queue1", "topicExchange", "sports.*");</code></pre>
                        <p class="text-gray-600 mt-3">队列会接收到匹配模式的消息</p>
                    </div>
                    <div class="border p-6 rounded-lg">
                        <h4 class="font-bold text-lg mb-3">Headers Exchange 绑定</h4>
                        <pre class="bg-gray-100 p-4 rounded text-sm"><code>Map&lt;String, Object&gt; headers = new HashMap&lt;&gt;();
headers.put("color", "red");
channel.queueBind("myQueue", "headersExchange", "", headers);</code></pre>
                        <p class="text-gray-600 mt-3">队列会根据头部字段匹配接收消息</p>
                    </div>
                </div>

                <h3 class="text-2xl font-semibold mt-8 mb-4 text-gray-800">绑定删除</h3>
                <div class="bg-gray-800 rounded-lg p-4 mb-8">
                    <pre class="text-gray-300 overflow-x-auto"><code>// 删除队列与交换机的绑定
channel.queueUnbind("queue1", "directExchange", "info");</code></pre>
                </div>
            </section>

            <!-- Application Scenarios -->
            <section class="mb-16">
                <h2 class="text-3xl font-bold mb-6 border-b pb-4">交换机类型的应用场景分析</h2>
                
                <div class="overflow-x-auto">
                    <table class="min-w-full divide-y divide-gray-200">
                        <thead class="bg-gray-50">
                            <tr>
                                <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">交换机类型</th>
                                <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">路由方式</th>
                                <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">典型应用场景</th>
                                <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">优点</th>
                            </tr>
                        </thead>
                        <tbody class="bg-white divide-y divide-gray-200">
                            <tr>
                                <td class="px-6 py-4 whitespace-nowrap">
                                    <div class="flex items-center">
                                        <div class="flex-shrink-0 h-10 w-10 bg-indigo-100 rounded-full flex items-center justify-center">
                                            <i class="fas fa-route text-indigo-600"></i>
                                        </div>
                                        <div class="ml-4">
                                            <div class="text-sm font-medium text-gray-900">Direct Exchange</div>
                                        </div>
                                    </div>
                                </td>
                                <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">路由键精确匹配</td>
                                <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
                                    <ul class="list-disc pl-5">
                                        <li>任务队列</li>
                                        <li>日志服务</li>
                                        <li>负载均衡</li>
                                    </ul>
                                </td>
                                <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">精确路由，简单高效</td>
                            </tr>
                            <tr>
                                <td class="px-6 py-4 whitespace-nowrap">
                                    <div class="flex items-center">
                                        <div class="flex-shrink-0 h-10 w-10 bg-emerald-100 rounded-full flex items-center justify-center">
                                            <i class="fas fa-broadcast-tower text-emerald-600"></i>
                                        </div>
                                        <div class="ml-4">
                                            <div class="text-sm font-medium text-gray-900">Fanout Exchange</div>
                                        </div>
                                    </div>
                                </td>
                                <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">无路由键，广播到所有队列</td>
                                <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
                                    <ul class="list-disc pl-5">
                                        <li>事件通知</li>
                                        <li>消息广播</li>
                                        <li>日志收集</li>
                                    </ul>
                                </td>
                                <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">简单广播，高并发支持</td>
                            </tr>
                            <tr>
                                <td class="px-6 py-4 whitespace-nowrap">
                                    <div class="flex items-center">
                                        <div class="flex-shrink-0 h-10 w-10 bg-amber-100 rounded-full flex items-center justify-center">
                                            <i class="fas fa-project-diagram text-amber-600"></i>
                                        </div>
                                        <div class="ml-4">
                                            <div class="text-sm font-medium text-gray-900">Topic Exchange</div>
                                        </div>
                                    </div>
                                </td>
                                <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">路由键模式匹配（通配符）</td>
                                <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
                                    <ul class="list-disc pl-5">
                                        <li>复杂消息路由</li>
                                        <li>多层次分类</li>
                                        <li>精准匹配</li>
                                    </ul>
                                </td>
                                <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">灵活路由，多级匹配</td>
                            </tr>
                            <tr>
                                <td class="px-6 py-4 whitespace-nowrap">
                                    <div class="flex items-center">
                                        <div class="flex-shrink-0 h-10 w-10 bg-purple-100 rounded-full flex items-center justify-center">
                                            <i class="fas fa-heading text-purple-600"></i>
                                        </div>
                                        <div class="ml-4">
                                            <div class="text-sm font-medium text-gray-900">Headers Exchange</div>
                                        </div>
                                    </div>
                                </td>
                                <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">消息头部属性匹配</td>
                                <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
                                    <ul class="list-disc pl-5">
                                        <li>复杂条件路由</li>
                                        <li>消息内容匹配</li>
                                        <li>多条件筛选</li>
                                    </ul>
                                </td>
                                <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">多维度匹配，灵活筛选</td>
                            </tr>
                        </tbody>
                    </table>
                </div>
            </section>

            <!-- Summary -->
            <section class="mb-16">
                <div class="bg-gray-50 rounded-xl p-8">
                    <h2 class="text-2xl font-bold mb-6 text-center">RabbitMQ 交换机类型选择指南</h2>
                    <div class="grid md:grid-cols-2 gap-8">
                        <div>
                            <h3 class="text-lg font-semibold mb-4 flex items-center">
                                <span class="w-6 h-6 bg-indigo-500 rounded-full flex items-center justify-center text-white mr-3">1</span>
                                需要精确路由到特定队列？
                            </h3>
                            <p class="text-gray-600 ml-9 mb-6">选择 <strong>Direct Exchange</strong>，通过精确的路由键匹配</p>
                            
                            <h3 class="text-lg font-semibold mb-4 flex items-center">
                                <span class="w-6 h-6 bg-emerald-500 rounded-full flex items-center justify-center text-white mr-3">2</span>
                                需要广播消息给所有消费者？
                            </h3>
                            <p class="text-gray-600 ml-9 mb-6">选择 <strong>Fanout Exchange</strong>，实现消息广播</p>
                        </div>
                        <div>
                            <h3 class="text-lg font-semibold mb-4 flex items-center">
                                <span class="w-6 h-6 bg-amber-500 rounded-full flex items-center justify-center text-white mr-3">3</span>
                                需要基于模式匹配的灵活路由？
                            </h3>
                            <p class="text-gray-600 ml-9 mb-6">选择 <strong>Topic Exchange</strong>，使用通配符匹配路由键</p>
                            
                            <h3 class="text-lg font-semibold mb-4 flex items-center">
                                <span class="w-6 h-6 bg-purple-500 rounded-full flex items-center justify-center text-white mr-3">4</span>
                                需要基于消息属性而非路由键？
                            </h3>
                            <p class="text-gray-600 ml-9">选择 <strong>Headers Exchange</strong>，根据消息头部属性路由</p>
                        </div>
                    </div>
                </div>
            </section>
        </article>
    </main>

    <!-- Footer -->
    <footer class="footer text-white py-8 px-4">
        <div class="container mx-auto max-w-5xl">
            <div class="flex flex-col md:flex-row justify-between items-center">
                <div class="mb-4 md:mb-0">
                    <h3 class="text-lg font-medium">技术小馆</h3>
                </div>
                <div>
                    <a href="http://www.yuque.com/jtostring" class="text-gray-300 hover:text-white transition-colors">
                        <i class="fas fa-external-link-alt mr-2"></i>
                        http://www.yuque.com/jtostring
                    </a>
                </div>
            </div>
        </div>
    </footer>

    <script>
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            flowchart: {
                useMaxWidth: false,
                htmlLabels: true,
                curve: 'basis'
            }
        });
    </script>
</body>
</html>
```